layui.use(['form', 'table','layuimini','element'], function () {
    var $ = layui.jquery,
        form = layui.form,
        table = layui.table,
        layuimini = layui.layuimini;

    /**
     * 初始化表单，要加上，不然刷新部分组件可能会不加载
     */
    form.render();

    var BoContent = {
        id: 'BoContentTable'
    };

    var column = [
        [
            {type: 'numbers'},
            {field: 'contentColumnName', title: '栏目', align: 'center'},
            {field: 'id', title: '编号', align: 'center'},
            {field: 'title', title: '标题', align: 'center'},
            {field: 'content', title: '内容', align: 'center'},
            {field: 'updateDate', title: '更新时间', minWidth: 120, align: 'center'},
            {templet: '#stateBtn', width: 170, align: 'center', title: '操作'}
        ]
    ];

    table.render({
        elem: '#' + BoContent.id,
        url: '/web/boContent/recycleList',
        toolbar: '#toolbarBtn',
        defaultToolbar: ['filter', 'exports', 'print'],
        cols: column,
        limits: [10, 15, 20, 25, 50, 100],
        limit: 15,
        page: true
    });

    /**
     * 点击彻底删除按钮
     * @param id
     */
    BoContent.thoroughlyDelete = function(id){
        layer.open({
            title: '彻底删除内容'
            ,content: '是否确定彻底删除该内容？'
            ,icon: 3
            ,btn: ['确定', '取消']
            ,yes: function(index, layero){
                layer.close(index);
                var indexLoad = layer.load(2);
                var url = '/web/boContent/thoroughlyDelete';
                $.post(url, {id: id}, function(data){
                    layer.close(indexLoad);
                    if(data.state == "200"){
                        layer.msg(data.message, {icon: 1});
                        table.reload(BoContent.id);
                    }else{
                        layer.msg(data.message, {icon: 2});
                    }
                })
            }
        });

        return false;
    };

    /**
     * 点击恢复按钮
     * @param id
     */
    BoContent.restore = function(id){
        layer.open({
            title: '恢复内容'
            ,content: '是否确定恢复该内容？'
            ,icon: 3
            ,btn: ['确定', '取消']
            ,yes: function(index, layero){
                layer.close(index);
                var indexLoad = layer.load(2);
                var url = '/web/boContent/restore';
                $.post(url, {id: id}, function(data){
                    layer.close(indexLoad);
                    if(data.state == "200"){
                        layer.msg(data.message, {icon: 1});
                        table.reload(BoContent.id);
                    }else{
                        layer.msg(data.message, {icon: 2});
                    }
                })
            }
        });

        return false;
    };

    //监听表格复选框选择
    // table.on('checkbox(currentTableFilter)', function (obj) {
    //     console.log(obj)
    // });

    //监听工具条
    table.on('tool(' + BoContent.id + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;

        if (layEvent === 'thoroughlyDelete') {
            BoContent.thoroughlyDelete(data.id);
        }else if(layEvent === 'restore'){
            BoContent.restore(data.id);
        }
    });

});